package com.jtpay.payresulthelper.util;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by Joe on 2017/10/21 15:44.
 */

public class SharedPreferenceUtil {
    private static int MODE = Context.MODE_PRIVATE;

    public String SP_READ(Context context, String Key) {
        return context.getSharedPreferences("UserManager", MODE).getString(Key, "");
    }

    public String SP_READ(Context context, String Key, String defValue) {
        return context.getSharedPreferences("UserManager", MODE).getString(Key, defValue);
    }

    public void SP_SAVE(Context context, String Key, String Value) {
        SharedPreferences.Editor localEditor = context.
                getSharedPreferences("UserManager", MODE).edit();
        localEditor.putString(Key, Value);
        localEditor.apply();
    }

    public boolean SP_READ_BOOLEAN(Context context, String Key) {
        return context.getSharedPreferences("UserManager", MODE).getBoolean(Key, false);
    }

    public void SP_SAVE_BOOLEAN(Context context, String Key, boolean Value) {
        SharedPreferences.Editor localEditor = context.
                getSharedPreferences("UserManager", MODE).edit();
        localEditor.putBoolean(Key, Value);
        localEditor.apply();
    }

    public int SP_READ_INTEGER(Context context, String Key) {
        return context.getSharedPreferences("UserManager", MODE).getInt(Key, 0);
    }

    public int SP_READ_INTEGER(Context context, String Key, int defValue) {
        return context.getSharedPreferences("UserManager", MODE).getInt(Key, defValue);
    }

    public void SP_SAVE_INTEGER(Context context, String Key, int Value) {
        SharedPreferences.Editor localEditor = context.
                getSharedPreferences("UserManager", MODE).edit();
        localEditor.putInt(Key, Value);
        localEditor.apply();
    }

    public void SP_CLEAN(Context context) {
        SharedPreferences.Editor localEditor = context.
                getSharedPreferences("UserManager", MODE).edit();
        localEditor.clear();
        localEditor.apply();
    }
}
